home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / BORLAND TURBO / 32SNIPIT.PAK / ADDALIAS.C next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.0 KB  |  92 lines

  1. // BDE32 3.x - (C) Copyright 1996 by Borland International
  2.  
  3. // addalias.c
  4. #include "snipit.h"
  5.  
  6. #define PARAM_LEN 200
  7.  
  8. //=====================================================================
  9. //  Function:
  10. //          AddAlias();
  11. //
  12. //  Description:
  13. //          This example shows how to add an alias to the BDE
  14. //          configuration file.
  15. //=====================================================================
  16. void
  17. AddAlias (void)
  18. {
  19.     hDBIDb      hDb = 0;                // Handle to the database
  20.     hDBICur     hCur = 0;               // Handle to a table
  21.     DBIResult   rslt;                   // Return value from IDAPI functions
  22.     CHAR        szParams[PARAM_LEN];    // Parameters to the alias
  23.     DBINAME     szAlias = "SNIPTEST";   // Name of the alias
  24.     UINT16      uNumRecs = 10;          // Number of records to display, 0=all
  25.  
  26.     Screen("*** Adding aliases to the configuration file ***\r\n");
  27.  
  28.     BREAK_IN_DEBUGGER();
  29.  
  30.     Screen("    Initializing IDAPI...");
  31.     rslt = DbiInit(NULL);
  32.     if (ChkRslt(rslt, "Init"))
  33.     {
  34.         return;
  35.     }
  36.  
  37.     // Enable trace information if the debug layer is enabled.
  38.     rslt = DbiDebugLayerOptions(DEBUGON | OUTPUTTOFILE, "SNIPIT.INF");
  39.     ChkRslt(rslt, "DebugLayerOptions");
  40.  
  41.     // szTblDirectory is set within SNIPIT to contain the fully
  42.     //   qualified path to the examples table directory, by default,
  43.     //   c:\bde\examples\tables.
  44.     strcpy(szParams, "PATH:");
  45.     strcat(szParams, szTblDirectory);
  46.  
  47.     // Add an alias for local tables.
  48.     Screen("    Add an Alias to IDAPI.CFG.");
  49.     rslt = DbiAddAlias(NULL, szAlias, szPARADOX, szParams, TRUE);
  50.     if (ChkRslt(rslt, "AddAlias") != DBIERR_NONE)
  51.     {
  52.         Screen("\r\n    Could not add alias to IDAPI.CFG.");
  53.     }
  54.     else
  55.     {
  56.         Screen("\r\n    Alias added to IDAPI.CFG.");
  57.     }
  58.  
  59.     // Open a database using this alias.
  60.     Screen("\r\n    Open a database using the created alias...");
  61.     rslt = DbiOpenDatabase(szAlias, NULL, dbiREADONLY, dbiOPENSHARED, NULL,
  62.                            NULL, NULL, NULL, &hDb);
  63.     ChkRslt(rslt, "OpenDatabase");
  64.  
  65.     // Notice that we do not have to specify the directory and that
  66.     //   DbiSetDirectory was not called - the directory information was set
  67.     //   in the alias.
  68.     Screen("\r\n    Open the vendors table using the created alias...");
  69.     rslt = DbiOpenTable(hDb, "vendors.db", NULL, NULL, NULL, 0, dbiREADONLY,
  70.                         dbiOPENSHARED, xltFIELD, FALSE, NULL, &hCur);
  71.     ChkRslt(rslt, "OpenTable");
  72.  
  73.     Screen("\r\n    Display the table...");
  74.     DisplayTable(hCur, uNumRecs);
  75.  
  76.     Screen("\r\n    Close the Database...");
  77.     rslt = DbiCloseDatabase(&hDb);
  78.     ChkRslt(rslt, "DeleteAlias");
  79.  
  80.     Screen("\r\n    Delete the alias...");
  81.     rslt = DbiDeleteAlias(NULL, szAlias);
  82.     ChkRslt(rslt, "DeleteAlias");
  83.  
  84.     // Shut down trace file
  85.     DbiDebugLayerOptions(0, NULL);
  86.  
  87.     Screen("\r\n    Exit IDAPI...");
  88.     DbiExit();
  89.  
  90.     Screen("\r\n*** End of Example ***");
  91. }
  92.